package com.xq.controller;

import org.apache.log4j.Logger;
import org.eclipse.jetty.http.HttpStatus;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;

public class ExceptionInterceptor implements Interceptor {

	Logger logger = Logger.getLogger(ExceptionInterceptor.class);
	@Override
	public void intercept(ActionInvocation ai) {
		try {
			ai.invoke();
		} catch (Exception e)
		{
			logger.debug(e);
			XQResponse response = new XQResponse(XQResponse.STATUS_EXCEPTION, "exception throws", e.getMessage());
			ai.getController().getResponse().setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
			ai.getController().renderJson(response);
		}
		
	}


}
